;  This file is part of tornado.
; 
;    tornado is free software: you can redistribute it And/Or modify
;    it under the terms of the GNU General Public License As published by
;    the Free Software Foundation, either version 3 of the License, Or
;    any later version.
; 
;    tornado is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE.  See the
;    GNU General Public License For more details.
; 
;    You should have received a copy of the GNU General Public License
;    along With tornado.  If Not, see <http://www.gnu.org/licenses/>. 2
; 

;
; Include the library header
;
IncludeFile "../library/tornado.pbi"


;
; Client & server use same include
;
XIncludeFile "shared.pbi"


;
; Get information about client
;
OpenConsole()

startClient:

Print("Nickname :")
nickname.s = Input()

Print("Server IP : ")
ip.s = Input()

;
; create client
;
*client = createGameClient(#GUID,nickname)

If *client
  
  ;
  ; Try to get some information about server , all infos are 
  ;
  *gameInfo.ServerInformation = getGameInformation(*client, ip, #GAME_PORT)
  
  If *gameInfo
    
    PrintN("Server found and give some information !")
    PrintN("Game session : "+*gameInfo\sessionName$)
    PrintN("Game version : "+*gameInfo\gameVersion$)
    PrintN("Connected player : "+Str(*gameInfo\nbPlayer)+"/"+Str(*gameInfo\maxPlayer) )
    
    ;
    ; if the server is protected by password
    ;
    password.s = ""
    
    If *gameInfo\isProtected = 1
      Print("Enter password : " )
      password = Input()
    Else
      PrintN("Password : no" )
    EndIf 
    
    PrintN("Press enter to join !")
    
    Input()
    
    ;
    ; join the server
    ;
    If joinServerGame(*client, *gameInfo, #VERSION, password)
      
      While #True 
        gameClientRun(*client)   
        
        
        
        
        Delay(10)  
      Wend 
      
      
      
    Else
      ErrorMessage.s = Space(512)
      getJoinError(*client,@ErrorMessage)
      PrintN("Error : "+ErrorMessage)
      Goto startClient
    EndIf 
    
    
  Else
    PrintN("No reponse from server")
    Goto startClient
  EndIf 
  
  
EndIf 
